package org.prem.jb.hibernate.attributeoverride;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class AttributeOverrideMain {

	public static void main(String[] args){
		
		Student student = new Student();
		student.setName("Prem Kumar");
		Address address = new Address();
		address.setDoorNo("42B");
		address.setStreet("2nd Old Murugan Talkies Street");
		address.setZipcode("625003");
		student.setAddress(address);
		Address collegeAddress = new Address();
		collegeAddress.setDoorNo("10B");
		collegeAddress.setStreet("Perundurai");
		collegeAddress.setZipcode("638003");
		student.setCollegeAddress(collegeAddress);
		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.save(student);
		//session.flush();
		session.getTransaction().commit();
		session.close();
		sessionFactory.close();
	}
}
